<!doctype html>
<html lang="en" xmlns:v-bind="http://www.w3.org/1999/xhtml" xmlns:v-on="http://www.w3.org/1999/xhtml" xmlns:v-model="http://www.w3.org/1999/xhtml">
<head>
    <meta charset="UTF-8">
    <title>Document</title>
    <link rel="stylesheet" href="../../vender/animate@3.5.0.min.css">
    <style>
        .list-item {
            display: inline-block;
            margin-right: 10px;
        }
        .list-enter-active, .list-leave-active {
            transition: all 1s;
        }
        .list-enter, .list-leave-to
            /* .list-leave-active for below version 2.1.8 */ {
            opacity: 0;
            transform: translateY(30px);
        }
    </style>
</head>
<body>

<div id="app">

    <my-component></my-component>
</div>


</body>
<script src="../../vender/vue@2.4.2.js"></script>

<script>
    var app=new Vue({
        el:'#app',
        components:{
            myComponent:{
                template:`<div id="list" class="demo">
                    <button @click="add">Add</button>
                    <button @click="remove">Remove</button>
                    <transition-group name="list" tag="div">
                        <span v-for="item of items" :key="item" class="list-item">{{item}}</span>
                    </transition-group>
                </div>`,
                data: function () {
                    return {
                        items:[1,2,3,4,5],
                        next:6
                    }
                },
                methods:{
                    _randomIdx: function () {
                        return Math.random()*this.items.length|0;
                    },
                    add: function () {
                        this.items.splice(this._randomIdx(),0,this.next++);
                        console.log('items:',this.items);
                    },
                    remove: function () {
                        this.items.splice(this._randomIdx(),1);
                    }
                }
            }
        }
    });



</script>
</html>